.TH std::system_error 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::system_error \- std::system_error

.SH Synopsis
   Defined in header <system_error>
   class system_error;               \fI(since C++11)\fP

   std::system_error is the type of the exception thrown by various library functions
   (typically the functions that interface with the OS facilities, e.g. the constructor
   of std::thread) when the exception has an associated std::error_code, which may be
   reported.

   std-system error-inheritance.svg

                                   Inheritance diagram

.SH Member functions

   constructor   constructs the system_error object
                 \fI(public member function)\fP
   operator=     replaces the system_error object
                 \fI(public member function)\fP
   code          returns error code
                 \fI(public member function)\fP
   what          returns an explanatory string
   \fB[virtual]\fP     \fI(virtual public member function)\fP

Inherited from std::exception

.SH Member functions

   destructor   destroys the exception object
   \fB[virtual]\fP    \fI(virtual public member function of std::exception)\fP
   what         returns an explanatory string
   \fB[virtual]\fP    \fI(virtual public member function of std::exception)\fP

.SH Example


// Run this code

 #include <iostream>
 #include <system_error>
 #include <thread>

 int main()
 {
     try
     {
         std::thread().detach(); // attempt to detach a non-thread
     }
     catch(const std::system_error& e)
     {
         std::cout << "Caught system_error with code "
                      "[" << e.code() << "] meaning "
                      "[" << e.what() << "]\\n";
     }
 }

.SH Possible output:

 Caught system_error with code [generic:22] meaning [Invalid argument]
